<?php
/*
 * @Author: your name
 * @Date: 2020-10-28 11:16:39
 * @LastEditTime: 2020-12-28 10:06:05
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙模块关联控制器
 * @FilePath: /special/application/adminapiv3/controller/module_manage/netfilter/NetfilterModuleRelationController.php
 */
namespace app\adminapiv3\controller\module_manage\netfilter;

use app\adminapiv3\controller\BaseController;
use app\adminapiv3\service\module_manage\netfilter\NetfilterModuleRelationService;
use think\facade\Request;

class NetfilterModuleRelationController extends BaseController
{
    /**
     * @name: 未添加模块主机列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-02 14:53:12
     */
    public function list ()
    {
        $input = Request::only(['name','ip','online'], 'post');

        $NetfilterModuleRelationService = new NetfilterModuleRelationService();
        $data = $NetfilterModuleRelationService->notAddedHostList($input);

        return $this->jsonOutPut($data);
    }

    /**
     * @name: 添加主机到模块
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-02 14:53:12
     */
    public function add ()
    {
        $input = Request::only(['host_id'], 'post');
        
        $this->validate($input, 'ModuleRelation.add');
        $NetfilterModuleRelationService = new NetfilterModuleRelationService();
        $NetfilterModuleRelationService->addRelation();

        $this->sendCommandToClient('client', 'modules');

        return $this->jsonOutPut([], true);
        

    }

    /**
     * @name: 从模块中删除主机
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-02 15:13:16
     */
    public function del ()
    {
        $input = Request::only(['host_id','module'], 'post');
        $this->validate($input, 'ModuleRelation.del');

        $NetfilterModuleRelationService = new NetfilterModuleRelationService();
        $NetfilterModuleRelationService->delRelation();

        $this->sendCommandToClient('client', 'modules');

        return $this->jsonOutPut([], true);
    }
}